package cn.yshujia.controller;

import cn.yshujia.domain.vo.ApiVO;
import cn.yshujia.domain.vo.SearchVO;
import cn.yshujia.service.impl.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author YShuJia
 * @create 2025/3/25
 * @description ClassifyLabelController
 */


@RestController
@Tag (name = "Service", description = "业务模块Api")
public class ServiceController {
	
	@Resource
	private ServiceServiceImpl service;
	
	@Resource
	private AlbumServiceImpl albumService;
	
	@Resource
	private ArticleServiceImpl articleService;
	
	@Resource
	private CommentServiceImpl commentService;
	
	@Resource
	private TreeHoleServiceImpl treeHoleService;
	
	@Resource
	private WebsiteServiceImpl websiteService;
	
	@Resource
	private LikeServiceImpl likeService;
	
	@GetMapping ("/search/{key}")
	@Operation (summary = "全局搜索功能")
	public ApiVO<SearchVO> searchByTask(@PathVariable String key) {
		return ApiVO.success(service.searchByTask(key));
	}
	
	@GetMapping ("/admin/service/count")
	@Operation (summary = "获取业务模块数据统计")
	public ApiVO<Map<String, Number>> count() {
		Map<String, Number> map = Map.of(
				"album", albumService.count(),
				"article", articleService.count(),
				"comment", commentService.count(),
				"treeHole", treeHoleService.count(),
				"website", websiteService.count(),
				"like", likeService.count()
		);
		return ApiVO.success(map);
	}
}
